package com.howbuy.base;

import java.io.File;

public class ToolBase {
	private static String baseReadPath="file/read/";
	
	private static String baseWritePath="file/return/";
	
	public static final String CHARSET="UTF-8";
	
	/** 
	 * 通过相对路径在file/read/下获取文件,path支持带盘符的绝对路径 不送文件名则处理对应文件夹下的所有文件 
	 */
	public static File[] readFile(String path,String fileName){
		if(!path.contains(":")){
			path=baseReadPath+path;
		}
		path=fomatPath(path);
		File file = new File(path);
		return file.listFiles();
	}
	
	public static File getWriteFile(String path,String fileName){
		if(!path.contains(":")){
			path=baseWritePath+path;
		}
		path=fomatPath(path);
		return new File(path+"/"+fileName);
	}
	
	static String fomatPath(String path){
		if(path.startsWith("/")){
			path=path.substring(1, path.length());
		}
		if(path.endsWith("/")){
			path=path.substring(0, path.length()-1);
		}
		return path;
	}
	
	
}
